/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

requirejs(['jquery', 'util', 'fancyBox', 'datatables', 'ztree', 'ztree_loader', 'ueditor', 'jUploader'], function($, Util, fancyBox, dataTables, ztree, treeLoader, umeditor, jUploader) {
    $(function() {

        uep = UM.getEditor('ueditorp');

        uep.ready(function() {
            uep.setHeight(220);
            uep.setWidth('100%');
            ueploaded = true;
        });

        // del
        $('#del-cate').click(function() {
            if (confirm('你确定要删除这个分类吗')) {
                $.post('?/vProduct/ajaxDelCategroy/', {
                    id: $('#cat_id').val()
                }, function(r) {
                    r = parseInt(r);
                    if (r > 0) {
                        alert('删除成功');
                        window.parent.fnDelSelectCat();
                        window.parent.location.reload();
                    }
                });
            }
        });
        // alter
        $('#save-cate').click(function() {
            $.post('?/vProduct/ajaxAlterCategroy/', {
                catid: $('#cat_id').val(),
                catname: $('#cat_name').val(),
                catdesc: uep.getContent(),
                catimage: $('#cat_image_src').val()
            }, function(r) {
                r = parseInt(r);
                if (r > 0) {
                    Util.Alert('保存成功');
                    // window.parent.fnReloadTree();
                }
            });
        });

        $.jUploader({
            button: 'alter_categroy_image',
            action: shoproot + '?/WdminAjax/BannerImageUpload/',
            onComplete: function(fileName, response) {
                var R = response;
                if (R.s > 0) {
                    $('#cat_image_src').val('static/banner/' + R.imgn);
                    $('#catimage').attr('src', shoproot + 'static/banner/' + R.imgn);
                    $('#cat_none_pic').hide();
                } else {
                    alert('上传图片失败，请联系技术支持');
                }
            }
        });
    });
});